import fetch, {
  RequestContentType,
  BaseChangeCourseResponse,
  BaseChangeCourseSimpleResponse,
} from './index'
import {
  ChangeCourseListData,
  ChangeCourseParam,
  AccountData,
  ChangeCourseTypeParam,
  ChangeCourseTypeData,
  StuPlanListData,
  IsChangeStuPlanData,
  TargetPlanParam,
  TargetPlanListData,
  CheckSaveParam,
  CheckSaveData,
  SaveChangeData,
  CourseplanParam,
  CourseplanData,
  IdencodeParam,
  IdencodeData,
  ConfirmParam,
  ConfirmData,
  AdjustAddParam,
  AdjustAddData,
} from '@/types/changeCourse'
import { XBusinesslineId } from '@/constants'

/**
 * 获取调出课程列表API
 * @param param ChangeCourseParam
 * @returns ChangeCourseListData
 */
export async function getchangeCourse(
  param: Partial<ChangeCourseParam>,
): Promise<BaseChangeCourseSimpleResponse<ChangeCourseListData>> {
  const { data } = await fetch.post<BaseChangeCourseSimpleResponse<ChangeCourseListData>>(
    '/api/adjust/changecourse/getchangecourselist',
    {
      'X-Businessline-Id': XBusinesslineId,
      ...param,
    },
    { contentType: RequestContentType.FORM_URLENCODED },
  )
  return data
}

/**
 * 获取用户信息
 * @param param ChangeCourseParam
 * @returns AccountData
 */
export async function getProfileInfo(
  param: Partial<ChangeCourseParam>,
): Promise<BaseChangeCourseSimpleResponse<AccountData>> {
  const { data } = await fetch.get<BaseChangeCourseSimpleResponse<AccountData>>(
    '/api/account/Profile/info',
    {
      'X-Businessline-Id': XBusinesslineId,
      ...param,
    },
    { contentType: RequestContentType.FORM_URLENCODED },
  )
  return data
}

/**
 * 获取调课场景API
 * @param param ChangeCourseTypeParam
 * @returns ChangeCourseTypeData
 */
export async function getchangecoursetype(
  param: Partial<ChangeCourseTypeParam>,
): Promise<BaseChangeCourseSimpleResponse<ChangeCourseTypeData>> {
  const { data } = await fetch.post<BaseChangeCourseSimpleResponse<ChangeCourseTypeData>>(
    '/api/adjust/changecourse/getchangecoursetype',
    {
      'X-Businessline-Id': XBusinesslineId,
      ...param,
    },
    { contentType: RequestContentType.FORM_URLENCODED },
  )
  return data
}

/**
 * 获取调出讲次API
 * @param param ChangeCourseTypeParam
 * @returns StuPlanListData
 */
export async function getStuPlanList(
  param: Partial<ChangeCourseTypeParam>,
): Promise<BaseChangeCourseResponse<StuPlanListData>> {
  const { data } = await fetch.get<BaseChangeCourseResponse<StuPlanListData>>(
    '/api/home/App/V2/StuPlan/getStuPlanList',
    {
      'X-Businessline-Id': XBusinesslineId,
      ...param,
    },
    { contentType: RequestContentType.FORM_URLENCODED },
  )
  return data
}

/**
 * 调换确认API
 * @param param TargetPlanParam
 * @returns IsChangeStuPlanData
 */
export async function isChangeStuPlan(
  param: Partial<TargetPlanParam>,
): Promise<BaseChangeCourseResponse<IsChangeStuPlanData>> {
  const { data } = await fetch.get<BaseChangeCourseResponse<IsChangeStuPlanData>>(
    '/api/home/App/V2/StuPlan/isChangeStuPlan',
    {
      'X-Businessline-Id': XBusinesslineId,
      ...param,
    },
    { contentType: RequestContentType.FORM_URLENCODED },
  )
  return data
}

/**
 * 获取调入讲次API
 * @param param TargetPlanParam
 * @returns TargetPlanListData
 */
export async function getTargetPlanList(
  param: Partial<TargetPlanParam>,
): Promise<BaseChangeCourseResponse<TargetPlanListData>> {
  const { data } = await fetch.post<BaseChangeCourseResponse<TargetPlanListData>>(
    '/api/home/App/V2/StuPlan/getTargetPlanList',
    {
      'X-Businessline-Id': XBusinesslineId,
      ...param,
    },
    { contentType: RequestContentType.FORM_URLENCODED },
  )
  return data
}

/**
 * 获取调换讲次确认信息API
 * @param param CheckSaveParam
 * @returns CheckSaveData
 */
export async function checkSaveChangeStuPlan(
  param: Partial<CheckSaveParam>,
): Promise<BaseChangeCourseResponse<CheckSaveData>> {
  const { data } = await fetch.post<BaseChangeCourseResponse<CheckSaveData>>(
    '/api/home/App/V2/StuPlan/checkSaveChangeStuPlan',
    {
      'X-Businessline-Id': 30,
      ...param,
    },
    { contentType: RequestContentType.FORM_URLENCODED },
  )
  return data
}

/**
 * 确认调换讲次API
 * @param param CheckSaveParam
 * @returns SaveChangeData
 */
export async function saveChangeStuPlan(
  param: Partial<CheckSaveParam>,
): Promise<BaseChangeCourseResponse<SaveChangeData>> {
  const { data } = await fetch.post<BaseChangeCourseResponse<SaveChangeData>>(
    '/api/home/App/V2/StuPlan/saveChangeStuPlan',
    {
      'X-Businessline-Id': 30,
      ...param,
    },
    { contentType: RequestContentType.FORM_URLENCODED },
  )
  return data
}

/**
 * 获取调入课程API
 * @param param CourseplanParam
 * @returns CourseplanData
 */
export async function getcourseplanlist(
  param: Partial<CourseplanParam>,
): Promise<BaseChangeCourseSimpleResponse<CourseplanData>> {
  const { data } = await fetch.post<BaseChangeCourseSimpleResponse<CourseplanData>>(
    '/api/adjust/changecourse/getcourseplanlist',
    {
      'X-Businessline-Id': 30,
      ...param,
    },
    { contentType: RequestContentType.FORM_URLENCODED },
  )
  data.data.pageNum = param.pageNum ? param.pageNum : '1'
  return data
}

/**
 * 获取idencode API
 * @param param IdencodeParam
 * @returns IdencodeData
 */
export async function getIdencode(
  param: Partial<IdencodeParam>,
): Promise<BaseChangeCourseSimpleResponse<IdencodeData>> {
  const { data } = await fetch.post<BaseChangeCourseSimpleResponse<IdencodeData>>(
    '/api/adjust/changecourse/idencode',
    {
      'X-Businessline-Id': 30,
      ...param,
    },
    { contentType: RequestContentType.FORM_URLENCODED },
  )
  return data
}

/**
 * 获取确认调课信息 API
 * @param param ConfirmParam
 * @returns ConfirmData
 */
export async function getConfirmIndex(
  param: Partial<ConfirmParam>,
): Promise<BaseChangeCourseResponse<ConfirmData>> {
  const { data } = await fetch.get<BaseChangeCourseResponse<ConfirmData>>(
    '/api/trade/PC/Adjust/Confirm/index',
    {
      'X-Businessline-Id': 30,
      ...param,
    },
    { contentType: RequestContentType.FORM_URLENCODED },
  )
  return data
}

/**
 * 确认调课提交 API
 * @param param AdjustAddParam
 * @returns AdjustAddData
 */
export async function adjustAdd(
  param: Partial<AdjustAddParam>,
): Promise<BaseChangeCourseResponse<AdjustAddData | string>> {
  const { data } = await fetch.post<BaseChangeCourseResponse<AdjustAddData | string>>(
    '/api/trade/PC/Adjust/Add/index',
    {
      'X-Businessline-Id': 30,
      ...param,
    },
    { contentType: RequestContentType.FORM_URLENCODED },
  )
  return data
}
